package com.chen.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.entity.Category;
import com.chen.entity.R;
import com.chen.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/page")
    public R page(int page, int pageSize) {
        Page<Category> page1 = categoryService.page1(page, pageSize);
        return R.success(page1);
    }

    @PostMapping
    public R add(@RequestBody Category category) {
        categoryService.save(category);
        return R.success(null);
    }

    @DeleteMapping
    public R delete(long id) {
        categoryService.delete(id);
        return R.success(null);
    }

    @PutMapping
    public R update(@RequestBody Category category) {
        categoryService.updateById(category);
        return R.success(null);
    }



    @GetMapping("/list")
    public R list( Category category){
        List<Category> list = categoryService.get(category);
        return R.success(list);
    }
}